package miracle.joker.design.chain_of_responsibility;

public class FileNameChecker implements Uploader {
    private String ALLOWED_NAME_FORMAT = "^\\w+\\.\\w+$";
    private Uploader next;

    public void setNext(Uploader uploader) {
        this.next = uploader;
    }

    @Override
    public void upload(File file) {
        if (!file.getName().matches(ALLOWED_NAME_FORMAT)) {
            System.out.println("File name is not valid.");
        } else if (next != null) {
            System.out.println("FNC");
            next.upload(file);
        } else {
            System.out.println("Upload successful.(FNC)");
        }
    }
}
